package com.ken.autocode.tools.generator.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MyStringUtil {

	// 处理数据库表名到Entity表名的转换,有非字母的处理掉 并变为大写
	public static String getEntityName(String tableName,boolean isHump) {
		String temp = tableName;
		char firstWord ;
		if(isHump){
			Matcher matcher = Pattern.compile("[\\_\\-\\—][0-9a-zA-Z]").matcher(tableName);
			while (matcher.find()){
				tableName = tableName.replace(matcher.group(),String.valueOf((char)(matcher.group().charAt(1)- 32)));
				temp =tableName;
				firstWord =tableName.charAt(0);
				temp =temp.replaceFirst(String.valueOf(firstWord),String.valueOf((char)(firstWord- 32)));
			}
		}else{
			temp = tableName.replaceAll("[-_]","").replace(String.valueOf(tableName.charAt(0)),String.valueOf((char)(tableName.charAt(0)- 32)));
		}
		return temp;
	}


	// 处理数据库表名到Entity表名的转换,有下划线的处理掉
	public static String getEntityPK(String str) {
		String temp = "";
		if(str==null || str.trim().length()<=0){
			return temp;
		}
		str = str.toLowerCase();
		temp = str.replaceAll("[-_]","");
		return temp;
	}



}
